<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-row>
      <el-col :span='22' :xs='24'>
        <el-form ref="form" :model="hpage_task" :rules="rules" label-width="100px" id="mvcfm">
          <el-button @click="potentialCustomerNTaskSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>保存</el-button>
          <el-button @click="gotoPage('/crm/sale/PotentialCustomerTask?'+vueparams+'')" type='primary' size="mini"><i class='fa fa-reply'></i>取消</el-button>
          <div class="form-unit">
            <span class="mvc-title-left"> 增加个人任务 </span>
          </div>
          <div>
            <el-row>
              <el-col :span="12">
                <el-form-item label="描述" prop="task_title">
                  <el-input v-model="hpage_task.task_title" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="预计完成日期" prop="task_predate">
                  <el-date-picker v-model="hpage_task.task_predate" type="date" style='width:100%' value-format="yyyy-MM-dd" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="优先级" prop="task_level">
                  <el-select style='width:100%' v-model="hpage_task.task_level">
                    <el-option label="正常" value="正常" />
                    <el-option label="加急" value="加急" />
                    <el-option label="紧急" value="紧急" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="状态" prop="task_state">
                  <el-radio-group v-model="hpage_task.task_state">
                    <el-radio-button label="未完成">未完成</el-radio-button>
                    <el-radio-button label="完成">完成</el-radio-button>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="共享" prop="task_share">
                  <el-radio-group v-model="hpage_task.task_share">
                    <el-radio-button label="公共的">公共的</el-radio-button>
                    <el-radio-button label="个人的">个人的</el-radio-button>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="安排给" prop="user_id">
                  {{hpage_task.user_id}}
                  <el-button @click="popTaskArrange('user_id','task_man')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="备注" prop="task_des">
                  <el-input type="textarea" v-model="hpage_task.task_des" ttparea=350></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="关联联系人" prop="task_relation">
                  <el-select style='width:100%' v-model="hpage_task.task_relation">
                    <el-option label="－－无－－" value='' />
                    <el-option v-for="dict in person" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <el-button @click="potentialCustomerNTaskSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>保存</el-button>
          <el-button @click="gotoPage('/crm/sale/PotentialCustomerTask?'+vueparams+'')" type='primary' size="mini"><i class='fa fa-reply'></i>取消</el-button>
        </el-form>
      </el-col>
      <el-col :span='2' :xs='24'>
        <el-menu default-active='active' class='menu-unit'>
          <el-menu-item v-for='item in Container'>
            <el-link @click="gotoMenu(item.url)" :type="'单个任务'===item.name?'primary':'default'">{{item.page_desc||item.name}}</el-link>
          </el-menu-item>
        </el-menu>
      </el-col>
    </el-row>
    <el-dialog :visible.sync="TaskArrangeVisible" append-to-body>
      <TaskArrange v-if="TaskArrangeVisible" ref="TaskArrange" :popparams="popparams"> </TaskArrange>
    </el-dialog>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import TaskArrange from "@/views/crm/autooffice/TaskArrange";
  export default {
    name: 'PotentialCustomerNTask',
    components: {
      TaskArrange,
    },
    props: ['popparams'],
    data() {
      return {
        TaskArrangeVisible: false,
        TaskArrangeValue: null,
        TaskArrangeDesc: null,
        vueparams: this.getVUEParams(""),
        hpage_task: {
          task_title: null,
          task_predate: null,
          task_level: null,
          task_state: null,
          task_share: null,
          user_id: null,
          task_des: null,
          task_relation: null,
        },
        person: [],
        loading: false,
        Container: null,
        rules: {
          task_title: [{
            required: true,
            message: "描述不能为空",
            trigger: 'blur',
          }],
        }
      }
    },
    created() {
      this.getData();
      this.loadContainerMenu({
        pid: "80299289AF2443B18EA545A4C0C37170",
        name: "客户管理右菜单",
        selected: "单个任务"
      }, 'Container', this.vueparams);
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/crm/sale/PotentialCustomerTask/potentialCustomerNTask?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      potentialCustomerNTaskSubmit(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/crm/sale/PotentialCustomerTask/potentialCustomerNTaskSubmit?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.gotoPage("/crm/sale/PotentialCustomerTask/potentialCustomerTask?" + this.vueparams, data);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      popTaskArrange(desc, value) {
        this.TaskArrangeVisible = true;
        this.TaskArrangeDesc = desc;
        this.TaskArrangeValue = value;
      },
      closeTaskArrange(value, desc) {
        this.TaskArrangeVisible = false;
        this.$set(this.hpage_task, this.TaskArrangeDesc, desc);
        this.$set(this.hpage_task, this.TaskArrangeValue, value);
      },
    },
  }
</script>
